#include "alarmlight.h"
#include <QPainter>
#include <QColor>
#include<QDebug>
AlarmLight::AlarmLight(QWidget *parent) : QWidget(parent)
{
m_outColorStart=QColor(255,255,255);
m_outColorEnd=QColor(163,163,163);
}
//绘制
void AlarmLight::paintEvent(QPaintEvent*pevent){
    int width=this->width();
    int height=this->height();
    int side=qMin(width,height);
    QPainter painter(this);
    painter.translate(width/2,height/2);
    drawBorderOut(&painter);
    drawLight(&painter);
}
void AlarmLight::drawBorderOut(QPainter*painter){
int radius=30;
painter->save();
painter->setPen(Qt::NoPen);
QLinearGradient borderGradient(0,-radius,0,radius);
borderGradient.setColorAt(0,m_outColorStart);
borderGradient.setColorAt(1,m_outColorEnd);
painter->setBrush(borderGradient);
painter->drawEllipse(-radius,-radius,radius*2,radius*2);

painter->restore();
}
void AlarmLight::drawLight(QPainter*painter){

int radius=26;
    painter->save();
    painter->setPen(Qt::NoPen);
    painter->setBrush(m_lightColor);
    painter->drawEllipse(-radius,-radius,radius*2,radius*2);
    painter->restore();
}
void AlarmLight::setBackGroundColor(const QColor&color){
m_lightColor=color;
update();
}
void AlarmLight::setRedLight(){
setBackGroundColor(QColor(255,107,107));
}
void AlarmLight::setOrangeLight(){
setBackGroundColor(QColor(211,169,139));
}
void AlarmLight::setYellowLight(){
setBackGroundColor(QColor(238,255,102));
}
void AlarmLight::setGreenLight(){
setBackGroundColor(QColor(24,189,155));
}
